# 多分类
from sklearn import datasets
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.utils import Bunch
import matplotlib.pyplot as plt
from sklearn.metrics import classification_report

iris = datasets.load_iris()
X = iris.data
y = iris.target

plt.scatter(X[:50,2], X[:50,3], c='r', label='Seatosa')
plt.scatter(X[50:100,2], X[50:100,3], c='blue', label='Versicolour')
plt.scatter(X[100:150,2], X[100:150,3], c='y', label='Virginica')
plt.ylabel("Petal.Width")
plt.xlabel('Petal.Length')
plt.legend()
plt.show()

plt.scatter(X[:50,0],X[:50,1],c='r',label='Seatosa')
plt.scatter(X[50:100,0],X[50:100,1],c='blue',label='Versicour')
plt.scatter(X[100:150,0], X[100:150,1], c='y', label='Virginica')
plt.ylabel("Sepal.Width")
plt.xlabel('Sepal.Length')
plt.legend()
plt.show()

X_train,X_test,y_train,y_test = train_test_split(X, y, test_size=0.3)
log_reg = LogisticRegression(solver='newton-cg', multi_class='multinomial')
# log_reg = LogisticRegression(solver='newton-cg', multi_class='multinomial')

log_reg.fit(X_train,y_train)
r2_score = log_reg.score(X_test, y_test)
print(r2_score)